package wetalk.software.bupt.com.wetalk.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import wetalk.software.bupt.com.wetalk.model.po.ChatUser;

/**
 * Created by hp on 2018/1/15.
 */

public class CollectionUtils {

    public static boolean isNotNull(Collection<?> collection) {
        if (collection != null && collection.size() > 0) {
            return true;
        }
        return false;
    }

    /** list转map
     *  以用户名为key
     * @return Map<String,BmobChatUser>
     * @throws
     */
    public static Map<String,ChatUser> list2map(List<ChatUser> users){
        Map<String,ChatUser> friends = new HashMap<String, ChatUser>();
        for(ChatUser user : users){
            friends.put(user.getUserName(), user);
        }
        return friends;
    }


    /** map转list
     * @Title: map2list
     * @return List<BmobChatUser>
     * @throws
     */
    public static List<ChatUser> map2list(Map<String,ChatUser> maps){
        List<ChatUser> users = new ArrayList<ChatUser>();
        Iterator<Map.Entry<String, ChatUser>> iterator = maps.entrySet().iterator();
        while(iterator.hasNext()){
            Map.Entry<String, ChatUser> entry = iterator.next();
            users.add(entry.getValue());
        }
        return users;
    }
}
